package com.shitou.test.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.shitou.pojo.Project;
import com.shitou.pojo.User;
import com.shitou.service.ProjectService;
import com.shitou.util.DateUtil;

import junit.framework.TestCase;

public class ProjectServiceTestCase extends TestCase {

	private ApplicationContext ctx;
	private ProjectService ps;
	
	@Override
	protected void setUp() throws Exception {
		ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		ps = (ProjectService) ctx.getBean("projectService");
	}
	
	public void testFind() {
		Project p = ps.findById(1);
		assertNotNull(p);
	}
	
	public void testFindAll() {
		List<Project> list = ps.findAll();
		assertEquals(2, list.size());
	}
	
	public void testSave() {
		Project p = new Project();
		p.setCreatedate(DateUtil.getNow());
		p.setName("Android开发");
		User user1 = new User();
		user1.setId(1);
		User user2 = new User();
		user2.setId(2);
		List<User> list = new ArrayList<User>();
		list.add(user1);
		list.add(user2);
		p.setUsers(list);
		ps.save(p);
	}
}
